/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.model.provider;

import java.util.List;

import com.siro.pm.I18nManager;
import com.siro.pm.model.Document;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since DocumentProvider.java v1.0
 */
public class DocumentProvider {

	public static String DOCUMENT_PROPERTY_NAME = I18nManager
			.getMessage("document.name");
	public static String DOCUMENT_PROPERTY_PROJECT = I18nManager
			.getMessage("document.project");
	public static String DOCUMENT_PROPERTY_PATH = I18nManager
			.getMessage("document.path");

	static IndexedContainer documentsContainer;
	static {
		documentsContainer = new IndexedContainer();
		documentsContainer.addContainerProperty(DOCUMENT_PROPERTY_NAME,
				String.class, "");
		documentsContainer.addContainerProperty(DOCUMENT_PROPERTY_PROJECT,
				String.class, "");
		documentsContainer.addContainerProperty(DOCUMENT_PROPERTY_PATH,
				String.class, "");
	}

	public static IndexedContainer getDocumentsData(List<Document> documents) {
		documentsContainer.removeAllItems();
		if (documents != null) {
			for (Document document : documents) {
				Item item = documentsContainer.addItem(document);
				item.getItemProperty(DOCUMENT_PROPERTY_NAME).setValue(
						document.getName());
				item.getItemProperty(DOCUMENT_PROPERTY_PROJECT).setValue(
						document.getProject().getName());
				item.getItemProperty(DOCUMENT_PROPERTY_PATH).setValue(
						document.getPath());
			}
		}
		return documentsContainer;
	}
}
